#include <iostream>
#include <vector>
#include <queue>


struct Node {
	int data;
	Node* prev;
	Node* next;

	Node(int x) {
		data = x;
		prev = NULL;
		next = NULL;
	}

	//添加一个节点
	void Add(Node* newNode) {
		this->next = newNode;
		newNode->prev = this;
	}

	void Delete() {
		this->prev->next = this->next;
		this->next->prev = this->prev;
		this->prev = NULL;
		this->next = NULL;
	}
};

/**
 * 手写双向循环链表
 */
void Solution1() {
	int n;
	std::cin >> n;

	if (n == 1) {
		std::cout << 1;
		return;
	}

	Node* head = new Node(1);

	Node* current = head;

	for (int i = 2; i <= n; i++) {
		Node* newNode = new Node(i);
		current->Add(newNode);
		current = newNode;
	}

	//首位相接
	current->Add(head);

	Node* p = head;
	while (true) {
		if (p->next == p) {
			std::cout << p->data;
			break;
		}
		p = p->next;
		p = p->next;

		Node* tmp = p;
		p = p->next;
		tmp->Delete();
	}
}

/**
 * 用数组模拟
 */
void Solution2() {
	int arr[110]{};

	int n;
	std::cin >> n;

	for (int i = 1; i < n; i++) {
		arr[i] = i + 1;
	}

	arr[n] = 1;

	int idx = 1;
	while (idx != arr[idx]) {
		idx = arr[idx];
		arr[idx] = arr[arr[idx]];
		arr[arr[idx]] = -1;
		idx = arr[idx];
	}
	std::cout << idx;
}

/**
 * 数组删除操作
 */
void Solution3() {
	int n;
	std::cin >> n;
	std::vector<int> children(n);
	for (int i = 0; i < n; i++) {
		children[i] = i + 1;
	}

	int cur = 0;
	while (children.size() > 1) {
		//用取模 模拟环
		cur = (cur + 3 - 1) % children.size();
		//每次删除之后size会减1
		children.erase(children.begin() + cur);
	}
	std::cout << children[0];
}

/**
 * 队列
 */
void Solution4() {
	int n;
	std::cin >> n;
	std::queue<int> q;
	for (int i = 1; i <= n; i++) {
		q.push(i);
	}

	while (q.size() > 1) {
		q.push(q.front());
		q.pop();
		q.push(q.front());
		q.pop();

		q.pop();
	}
	std::cout << q.front();
}

/**
 * 队列2
 */
void Solution5() {
	int n;
	std::cin >> n;
	std::queue<int> q;
	for (int i = 1; i <= n; i++) {
		q.push(i);
	}

	int cur = 1;
	while (q.size() > 1) {
		//每次出队后，检查一下，是不是报到3的人
		//是的话，就真的抹掉了，不是那就再入队
		int tmp = q.front();
		q.pop();

		if (cur == 3) {
			cur = 1;
		}
		else {
			q.push(tmp);
			cur++;
		}
	}
	std::cout << q.front();
}


/**
 *
 * 约瑟夫环
 *
 */
int main() {

	Solution5();

	return 0;
}



